<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录注册系统</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f2f2f2;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            padding: 20px;
        }

        .container {
            background-color: white;
            padding: 40px 60px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 400px;
        }

        .form-title {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
        }

        .form-group {
            margin-bottom: 20px;
        }

        input[type="text"],
        input[type="email"],
        input[type="password"] {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            transition: border-color 0.3s ease;
        }

        input[type="text"]:focus,
        input[type="email"]:focus,
        input[type="password"]:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 8px rgba(52, 152, 219, 0.2);
        }

        .remember-forgot {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            font-size: 0.9em;
            color: #7f8c8d;
        }

        .remember-me {
            display: flex;
            align-items: center;
        }

        .remember-me input {
            width: auto;
            margin-right: 8px;
        }

        button {
            background-color: #3498db;
            color: white;
            padding: 12px 25px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1em;
            width: 100%;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #2980b9;
        }

        .register-link {
            text-align: center;
            margin-top: 20px;
            color: #7f8c8d;
        }

        .register-link a {
            color: #3498db;
            text-decoration: none;
            font-weight: bold;
        }

        .error-message {
            color: #e74c3c;
            font-size: 0.9em;
            margin-top: 5px;
            display: none;
        }

        .success-message {
            color: #2ecc71;
            font-size: 0.9em;
            margin-top: 5px;
            display: none;
        }

        .toggle-form {
            text-align: center;
            margin-top: 30px;
        }

        .toggle-form button {
            background-color: #ecf0f1;
            color: #2c3e50;
            border: 1px solid #ddd;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .toggle-form button:hover {
            background-color: #3498db;
            color: white;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="form-title">用户登录系统</h1>
        
        <!-- 登录表单 -->
        <form id="loginForm" class="form-group">
            <div class="form-group">
                <label for="username">用户名：</label>
                <input type="text" id="username" placeholder="请输入用户名" required>
                <div id="usernameError" class="error-message"></div>
            </div>
            
            <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" id="password" placeholder="请输入密码" required>
                <div id="passwordError" class="error-message"></div>
            </div>
            
            <div class="remember-forgot">
                <label class="remember-me">
                    <input type="checkbox"> 记住我
                </label>
                <a href="#">忘记密码？</a>
            </div>
            
            <button type="submit">登录</button>
            <div id="loginSuccess" class="success-message"></div>
        </form>

        <!-- 注册表单 -->
        <form id="registerForm" class="form-group" style="display: none;">
            <div class="form-group">
                <label for="registerUsername">用户名：</label>
                <input type="text" id="registerUsername" placeholder="请输入用户名" required>
                <div id="registerUsernameError" class="error-message"></div>
            </div>
            
            <div class="form-group">
                <label for="registerEmail">邮箱：</label>
                <input type="email" id="registerEmail" placeholder="请输入邮箱" required>
                <div id="registerEmailError" class="error-message"></div>
            </div>
            
            <div class="form-group">
                <label for="registerPassword">密码：</label>
                <input type="password" id="registerPassword" placeholder="请输入密码" required>
                <div id="registerPasswordError" class="error-message"></div>
            </div>
            
            <div class="form-group">
                <label for="confirmPassword">确认密码：</label>
                <input type="password" id="confirmPassword" placeholder="确认密码" required>
                <div id="confirmPasswordError" class="error-message"></div>
            </div>
            
            <button type="submit">注册</button>
            <div id="registerSuccess" class="success-message"></div>
        </form>

        <div class="toggle-form">
            <button onclick="showRegisterForm()">还没有账号？立即注册</button>
        </div>
    </div>

    <script>
        // 登录表单验证
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            let isValid = true;

            // 清除之前的错误提示
            document.getElementById('usernameError').style.display = 'none';
            document.getElementById('passwordError').style.display = 'none';
            document.getElementById('loginSuccess').style.display = 'none';

            // 验证逻辑
            if (username === '') {
                showError('usernameError', '用户名不能为空');
                isValid = false;
            } else if (password === '') {
                showError('passwordError', '密码不能为空');
                isValid = false;
            } else if (username !== 'admin' || password !== '123456') { // 这里应该连接后端验证
                showError('passwordError', '用户名或密码错误');
                isValid = false;
            }

            if (isValid) {
                showSuccess('loginSuccess', '登录成功！即将跳转到个人中心...');
                setTimeout(() => {
                    // window.location.href = '/dashboard';
                }, 1500);
            }
        });

        // 注册表单验证
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const registerUsername = document.getElementById('registerUsername').value;
            const registerEmail = document.getElementById('registerEmail').value;
            const registerPassword = document.getElementById('registerPassword').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            let isValid = true;

            // 清除之前的错误提示
            document.getElementById('registerUsernameError').style.display = 'none';
            document.getElementById('registerEmailError').style.display = 'none';
            document.getElementById('registerPasswordError').style.display = 'none';
            document.getElementById('confirmPasswordError').style.display = 'none';
            document.getElementById('registerSuccess').style.display = 'none';

            // 验证逻辑
            if (registerUsername === '') {
                showError('registerUsernameError', '用户名不能为空');
                isValid = false;
            } else if (!validateUsername(registerUsername)) {
                showError('registerUsernameError', '用户名需包含字母和数字，长度3-10位');
                isValid = false;
            }

            if (registerEmail === '') {
                showError('registerEmailError', '邮箱不能为空');
                isValid = false;
            } else if (!validateEmail(registerEmail)) {
                showError('registerEmailError', '请输入有效的邮箱地址');
                isValid = false;
            }

            if (registerPassword === '') {
                showError('registerPasswordError', '密码不能为空');
                isValid = false;
            } else if (!validatePassword(registerPassword)) {
                showError('registerPasswordError', '密码需8位以上，包含大小写字母和数字');
                isValid = false;
            }

            if (confirmPassword === '') {
                showError('confirmPasswordError', '确认密码不能为空');
                isValid = false;
            } else if (registerPassword !== confirmPassword) {
                showError('confirmPasswordError', '两次输入的密码不一致');
                isValid = false;
            }

            if (isValid) {
                showSuccess('registerSuccess', '注册成功！请登录查看您的账户...');
                setTimeout(() => {
                    // 切换回登录表单
                    document.getElementById('loginForm').style.display = 'block';
                    document.getElementById('registerForm').style.display = 'none';
                }, 1500);
            }
        });

        // 切换表单显示
        function showRegisterForm() {
            document.getElementById('loginForm').style.display = 'none';
            document.getElementById('registerForm').style.display = 'block';
        }

        // 通用错误提示
        function showError(elementId, message) {
            document.getElementById(elementId).textContent = message;
            document.getElementById(elementId).style.display = 'block';
        }

        // 通用成功提示
        function showSuccess(elementId, message) {
            document.getElementById(elementId).textContent = message;
            document.getElementById(elementId).style.display = 'block';
        }

        // 用户名验证
        function validateUsername(username) {
            return /^[a-zA-Z0-9]{3,10}$/.test(username);
        }

        // 邮箱验证
        function validateEmail(email) {
            return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
        }

        // 密码验证
        function validatePassword(password) {
            return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/.test(password);
        }
    </script>
</body>
</html>